package sy.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sy.dao.AppCommentDaoI;
import sy.model.AppComment;
import sy.model.AppComplaint;
@Repository("appCommentDao")
public class AppCommentDaoImpl implements AppCommentDaoI{
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	private Session getCurrentSession(){
		return this.getSessionFactory().getCurrentSession();
	}

	@Override
	public Serializable save(AppComment appComment) {
		// TODO Auto-generated method stub
		return this.getCurrentSession().save(appComment);
	}

	@Override
	public List<AppComment> listAppCommentBySysAccountId(String sysAccountId) {
		// TODO Auto-generated method stub
		String hql = "from AppComment where sysAccountId = :sysAccountId";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setString("sysAccountId", sysAccountId);
		return query.list();
	}
	
	@Override
	public List<AppComment> getList() {
		// TODO Auto-generated method stub
		return getCurrentSession().createQuery("from AppComment").list();
	}
}
